package com.ocean.redflagtest.mvvm.views.activitys

import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.graphics.Color
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast

import com.ocean.redflagtest.R
import com.ocean.redflagtest.mvvm.base.BaseActivity
import com.ocean.redflagtest.mvvm.models.entity.CircleModel
import com.ocean.redflagtest.mvvm.viewmodels.MainViewModel
import com.ocean.redflagtest.mvvm.views.ui.OceanCircleView
import com.scwang.wave.MultiWaveHeader

class MainActivity : BaseActivity<MainViewModel>() {
    private var multiWaveHeader: MultiWaveHeader? = null
    private var oceanCircleView: OceanCircleView? = null


    private val ids = intArrayOf(R.id.item1, R.id.item2, R.id.item3, R.id.item4, R.id.item5)
    private val layouts = arrayOfNulls<LinearLayout>(5)
    private val tips = arrayOf("首页", "思想建设", "组织建设", "作风建设", "我的建设")

    private val tvIds = intArrayOf(R.id.tv1, R.id.tv2, R.id.tv3, R.id.tv4, R.id.tv5)
    private val textViews = arrayOfNulls<TextView>(5)


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initViews()
        initData()
    }

    fun initViews() {
        multiWaveHeader = findViewById(R.id.waveHeader)
        oceanCircleView = findViewById(R.id.oceanView)
        for (i in ids.indices) {
            textViews[i] = findViewById(tvIds[i])
            layouts[i] = findViewById(ids[i])
            layouts[i]?.setOnClickListener(View.OnClickListener {
                Toast.makeText(this@MainActivity, "点击了" + tips[i], Toast.LENGTH_SHORT).show()
                setTab(i)
            })
        }
    }

    fun initData() {
        viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)
        viewModel.getCircleDatas()!!.observe(this, Observer { circleModels ->
            oceanCircleView!!.datas = circleModels
            oceanCircleView!!.startDraw()
        })
    }

    fun setTab(position: Int) {
        for (i in textViews.indices) {
            if (position == i) {
                textViews[i]?.setTextColor(Color.parseColor("#f9e728"))
            } else {
                textViews[i]?.setTextColor(Color.WHITE)
            }
        }
    }


}
